<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core as C;
use classlib\core\controller;
class Cshare extends controller {
	public function douser() {
		$view  = C\view::inst('json');
		Cadmin::islogin($view);
		list($start, $limit, $sorts) = Cadmin::offset();
		$query = input::post('query');
		$query = trim($query);
		$where = array();
		if ($query) {
			$where = array(
				array('email', '%'.$query.'%', \classlib\orm::OP_LIKE),
				array('nickname', '%'.$query.'%', \classlib\orm::OP_LIKE, \classlib\orm::OP_OR)
			);
		}
		$orm   = C\model::load('pro.pl.userinfo');
		$total = $orm->get_total($where);
		$list  = array();
		if ($total > 0) {
			$field = 'userid as id, nickname as name, email';
			$list  = $orm->get_list($start, $limit, $where, $field, $sorts);
			foreach ($list as &$item) {
				if (!empty($item['email'])) {
					$item['name'] .= '['.$item['email'].']';
				}
				unset($item['email']);
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
	
	public function dotags() {
		$view  = C\view::inst('json');
		Cadmin::islogin($view);
		list($start, $limit, $sorts) = Cadmin::offset();
		$query = input::post('query');
		$query = trim($query);
		$where = array();
		if ($query) {
			$where[] = array('name', '%'.$query.'%', \classlib\orm::OP_LIKE);
		}
		$orm   = C\model::load('pro.inc.tags');
		$total = $orm->get_total($where);
		$list  = array();
		if ($total > 0) {
			$list  = $orm->get_list($start, $limit, $where, 'id, name', $sorts);
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
	
	public function dostar() {
		$view  = C\view::inst('json');
		Cadmin::islogin($view);
		list($start, $limit, $sorts) = Cadmin::offset();
		$query   = input::post('query');
		$where   = array();
		if ($query) {
			$where = array('name'=>array('%'.$query.'%', \classlib\orm::OP_LIKE));
		}
		$orm   = C\model::load('pro.inc.star');
		$total = $orm->get_total($where);
		$list  = array();
		if ($total > 0) {
			$list  = $orm->get_list($start, $limit, $where, 'id, name, star', $sorts);
			foreach ($list as &$item) {
				$item['name'] = htmlspecialchars_decode($item['name']);
				$item['name'].= '['.$item['star'].']';
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}
